package com.lagou.edu.service.impl;

import com.lagou.edu.dao.ResumeDao;
import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ResumeServiceImpl implements ResumeService {

	@Autowired
	private ResumeDao resumeDao;


	@Override
	public List<Resume> selectResumeList() {
		return resumeDao.findAll();
	}

	@Override
	public Resume selectResume(Resume resume){
		try{
			Example<Resume> resumeParamEntity = Example.of(resume);
			Optional<Resume> resumeFindResultEntity = resumeDao.findOne(resumeParamEntity);
			return resumeFindResultEntity.get();
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public Resume insertResume(Resume resume)  {
		try{
			return resumeDao.save(resume);
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public Resume updateResume(Resume resume) {
		try{
			return resumeDao.save(resume);
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public void deleteResume(Resume resume) {
		try{
			resumeDao.deleteById(resume.getId());
		}catch (Exception e){
			e.printStackTrace();
		}
	}
}
